<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增工程文件上传')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-blueprint-add" th:object="${pId}">
            <div class="form-group">
                <div class="col-sm-8" style="display: none">
                    <input name="pId" class="form-control" th:value="${pId}">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">文件名称：</label>
                <div class="col-sm-8">
                    <input id="pFileName" name="pFileName" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group" >
                <label class="col-sm-3 control-label" >文件类型：</label>
                <div class="col-sm-8">
                    <select id="pFileType" name="pFileType" th:with="type=${@dict.getType('sys_file_type')}" >
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}">
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">上传文件：</label>
                <div class="col-sm-8">
                    <input id="pFileUploading" name="pFileUploading" class="form-control" type="file" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">文件备注：</label>
                <div class="col-sm-8">
                    <input id="pFileRemark" name="pFileRemark" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group" style="display: none">
                <label class="col-sm-3 control-label">文件上传时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input id="pFileTime" name="pFileTime"  class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                    </div>
                </div>
            </div>
            <div class="form-group" style="display: none">
                <label class="col-sm-3 control-label is-required">项目id：</label>
                <div class="col-sm-8">
                    <input id="filePro" name="filePro" class="form-control" type="hidden" th:value="${pId}" >
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script type="text/javascript">
        var prefix = ctx + "system/blueprint"
        $("#form-blueprint-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                uploadFile();
            }
        }

        function uploadFile() {
            var formData = new FormData();
            if ($('#pFileUploading')[0].files[0] == null) {
                $.modal.alertWarning("请先选择文件路径");
                return false;
            }
            formData.append('pFileName', $("#pFileName").val());
            formData.append('pFileType', $("#pFileType").val());
            formData.append('pFileTime', $("#pFileTime").val());
            formData.append('pFileRemark', $("#pFileRemark").val());
            formData.append('filePro', $("#filePro").val());
            formData.append('file', $('#pFileUploading')[0].files[0]);
            $.ajax({
                url: prefix + "/add/",
                type: 'post',
                cache: false,
                data: formData,
                processData: false,
                contentType: false,
                dataType: "json",
                success: function(result) {
                    $.operate.successCallback(result);
                }
            });
        }


        $("input[name='pFileTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
    </script>
</body>
</html>